package chat.ui;

import java.awt.Component;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.tree.TreeCellRenderer;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;

class MyTreeCellRenderer implements TreeCellRenderer {
    private JLabel label;
    private String IconPath = "online10x10.png";
    private Image group = Toolkit.getDefaultToolkit().createImage("group20x20.png");
    final private String ONLINE = "online.png";
	final private String DND = "donotdisturb.png";
	final private String BUSY = "busy.png";
	final private String OFFLINE = "offline.png";
    
    public MyTreeCellRenderer() {
        label = new JLabel();
    }

    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        Object o = ((DefaultMutableTreeNode) value).getUserObject();
        if (o instanceof GroupTreeNode) {
            GroupTreeNode node = (GroupTreeNode) o;
           // label.setIcon(new ImageIcon(node.getFlagIcon()));
           // Image img1 = java.awt.Toolkit.getDefaultToolkit().getImage(getClass().getResource("C:\\online.png"));
            Image img2 = null;
            String icon = node.getFlagIcon();
            switch (icon){
            	case "ONLINE": img2 = Toolkit.getDefaultToolkit().createImage(ONLINE); break;
            	case "BUSY": img2 = Toolkit.getDefaultToolkit().createImage(BUSY); break;
            	case "DND": img2 = Toolkit.getDefaultToolkit().createImage(DND); break;
            	case "OFFLINE": img2 = Toolkit.getDefaultToolkit().createImage(OFFLINE); break;
            }
            
            label.setIcon(new ImageIcon (img2));
            label.setText(node.getName());
            label.setToolTipText(node.getStatus());
            
        } else {
            label.setIcon(new ImageIcon(group));
            label.setText("" + value);
            label.setToolTipText("");
        }
        return label;
    }
}
